<?php
function smarty_function_byteconvert($params, &$smarty)
{
	$bytes = $params["value"];
	
	if($bytes < 1024)	return "{$bytes}B";
	
	$bytes = ($bytes / 1024);
	if($bytes < 1024)	return round($bytes)."KiB";
	
	$bytes = ($bytes / 1024);
	if($bytes < 1024)	return round($bytes,2)."MiB";
	
	$bytes = ($bytes / 1024);
	if($bytes < 1024)	return round($bytes,2)."GiB";
	
	$bytes = ($bytes / 1024);
	if($bytes < 1024)	return round($bytes,2)."TiB";
}